home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-06 | 2.0 KB | 71 lines | [TEXT/MSET] |
- \ 01Dec93 DBH redefined >dispose so killer is not reqired. saved 46 bytes
-
- (*
- >heap and >dispose allow us to dynamically create nameless objects from
- the heap in the same way Neon did. The advantage to using this method over,
- for example OBJHANDLE, is that we can simply send messages straight to the
- object if we store the returned pointer in a value or local variable
- (we need not first send the obj: method first). Of course since we are
- locking a handle we should be careful not to create too many of these
- objects such that the heap is fragmented. This should not be a problem for
- relatively small or transient objects created with >heap.
- *)
-
- : PUSHA0 $ 2D08 w, ; immediate \ move.l a0,-(a6)
- : POPA0 $ 205E w, ; immediate \ move.l (a6)+,a0
-
- \ This stuff allows Neon pointer type objects in Mops to allow a programmer
- \ to choose whether to use handle type objects after the conversion to
- \ Mops is complete.
-
- ObjHandle newObjVar \ temporary handle to create new obj ala Mops
-
- \ handle killer \ used in killhandle
-
- \ : KILLHANDLE ( handle -- ) \ new version. dbh 4/20/92
- \ put: killer
- \ release: killer ;
-
- : >heap { ^class \ objHdl objLen -- ^obj }
-
- \ pinched from NEWOBJ:, but save obj length for erase
- ^class cl>len 8 + dup -> objLen new: newObjVar
-
- moveHi: newObjVar \ debatable
- get: newObjVar -> objHdl \ save handle
-
- ptr: newObjVar objLen erase \ clear it like Neon
-
- \ let mops do its thing
- ^class obj: newObjVar make_obj
-
- \ do not unlock, cannot use newObjVar
- \ as classinit: may cause >heap to be re-entered
- objHdl @ 8 +
- ;
-
- : >dispose ( ^obj -- ) \ note resolution of forward definition
- 8 - popA0 call RecoverHandle pushA0
- ?dup
- IF
- put: newObjVar \ this is a handle method
- newObjVar release: handle \ note message to class to override objhandle release: !!
- THEN
- ;
-
- endload
-
- *** EXAMPLE USE
-
- ' null value heapRect \ storage for our object
-
- : go
- ['] rect+ >heap -> heapRect \ create a rect+ from the heap
- draw: heapRect \ look ma, no obj:
- heapRect >dispose \ return memory to the heap, must not use heapRect now
- ;
-
-
-
-
-